package org.example.controller;

import org.example.model.User;
import org.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/login/{id}")
    public String login(@PathVariable int id,String username, String password) {
        System.out.println(id);
        System.out.println(username);
        System.out.println(password);
        return "success";
    }

    @PostMapping("/login")
    public String login(String username, String password) {
        System.out.println(username);
        System.out.println(password);
        return "success";
    }

    @GetMapping("/getUserList")
    public List<User> getUserList(String username) {
        List<User> userList = userService.getUserList(username);
        return userList;
    }

    @PutMapping("/addUser")
    public String addUser(@RequestBody User user){
        System.out.println(user.getSex());
       int i=userService.addUser(user);
       if (i>0){
           return "success";
       }
       return "fail";
    }

    @PostMapping("updateUser")
    public String updateUser(@RequestBody User user){
       String msg= userService.updateUser(user);
       return msg;
    }

    @DeleteMapping("/deleteUser/{id}")
    public String deleteUser(@PathVariable int id){
       String msg = userService.deleteUser(id);
       return  msg;
    }














}
